package tasks;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import api.Client2Master;

public class InvertedIndexClient {
	public static void main(String[] args){
		String masterName = args[0];
		
		//TODO change to input/output dir
		InvertedIndexTask task = new InvertedIndexTask("invertedindex/in.txt", "invertedindex");
		
		if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }
		
		try {
			long startTime = System.currentTimeMillis();
			Registry registry = LocateRegistry.getRegistry(masterName);
			Client2Master master = (Client2Master)registry.lookup(Client2Master.SERVICE_NAME);
			master.addTask(task);
			long workerTime = master.finish();
			long endTime = System.currentTimeMillis();
			System.out.println("Time seen by the client: " + (endTime-startTime));
			System.out.println("Time seen by workers: " + workerTime);
			System.out.println("DONE!!!");
			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        
	}
}
